home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / boot / czesc_2 / saferpatches / source.lha / Source / SaferStartup.a < prev    next >
Text File  |  1992-10-04  |  3KB  |  158 lines

  1.         include     "all.i"
  2.         include     "exec/types.i"
  3.  
  4. AbsExecBase    equ        4
  5. KICK12        equ        33
  6.  
  7. ;    Call a library function (Base in A6)
  8. libcall     macro
  9.         jsr    _LVO\1(A6)
  10.         endm
  11.  
  12. ;    Call a c (or assembler function)
  13. call        macro
  14.         bsr    @\1
  15.         endm
  16.  
  17. ;    Imports
  18.         xref        _LinkerDB
  19.         xref        @NewSetFunction
  20.         xref        @MakeHead
  21.         xref        @FindPatches
  22.  
  23.         section     Startup,code
  24. Startup:    move.l        (AbsExecBase).W,A6
  25.         moveq.l     #0,D4
  26.  
  27. ;    Get pointer to our Process.
  28.         move.l        ThisTask(A6),A4
  29.  
  30. ;    Run from Workbench ?
  31.         tst.l        pr_CLI(A4)
  32.         bne        FromCLI           ; No
  33.  
  34. ;    Wait for Workbench startup-message.
  35.         lea        pr_MsgPort(A4),A0
  36.         libcall     WaitPort
  37.         lea        pr_MsgPort(A4),A0
  38.         libcall     GetMsg
  39.         move.l        D0,D4
  40.  
  41. ;    Open dos. (Will not be closed, our function uses it)
  42. FromCLI:    lea        _LinkerDB,A4
  43.         lea        DOSNAME(PC),A1
  44.         moveq.l     #KICK12,D0
  45.         libcall     OpenLibrary
  46.         move.l        D0,(A4)          ; _DOSBase
  47.  
  48.         beq        NoDos
  49.  
  50. ;    Are we already installed ?
  51.         jsr        @FindPatches      ; cant use pc-rel
  52.         tst.l        D0
  53.         beq        FirstTime
  54.         lea        INSTALLED(PC),A0
  55.         moveq.l     #INSTALL_sizeof,D3
  56.         call        PrintMes
  57.         bra        NoHead
  58.  
  59. ;    Init Semaphore
  60. FirstTime:    lea        _SetFuncSemaphore-DT(A4),A0
  61.         libcall     InitSemaphore
  62.  
  63. ;    Create the list header
  64.         sub.l        A0,A0
  65.         jsr        @MakeHead         ; can't use pc-rel here
  66.         move.l        D0,_MainHeader-DT(A4)
  67.         beq        NoHead
  68.  
  69. ;    Patch SetFunction
  70.         move.l        #_LVOSetFunction,A0
  71.         move.l        A6,A1
  72.         move.l        #@NewSetFunction,D0
  73.         jsr        0(A6,A0.W)            ; SetFunction
  74.         move.l        D0,_OldSetFuncPtr-DT(A4)
  75.         beq        NoPatch           ; oops !
  76.  
  77. ;    Output message
  78.         lea        MESSAGE(PC),A0
  79.         moveq.l     #MESSAGE_sizeof,D3
  80.         call        PrintMes
  81.  
  82. ;    Remove segments from list.
  83.         lea        Startup-4(PC),A0
  84.         clr.l        (A0)
  85.         bra        Started
  86.  
  87. NoPatch:    move.l        _MainHeader-DT(A4),A1
  88.         moveq.l     #12,D0           ; Header size
  89.         libcall     FreeMem
  90.  
  91. NoHead:     move.l        (A4),A1            ; _DOSBase
  92.         libcall     CloseLibrary
  93.  
  94. ;    Started from WB ?
  95. Started:    tst.l        D4
  96.         beq.b        Done           ; No
  97.  
  98. ;    Forbid so Workbench can't unload us before we are done.
  99.         move.l        (AbsExecBase).W,A6
  100.         libcall     Forbid
  101.         move.l        D4,A1
  102.         libcall     ReplyMsg
  103. Done:
  104. NoDos:        moveq.l     #0,D0
  105.         rts
  106.  
  107. ;    Output a message.
  108. @PrintMes:    move.l        A0,D2
  109.         move.l        (A4),A6            ; DOSBase
  110.         libcall     Output
  111.         move.l        D0,D1
  112.         beq        NoStdout
  113.  
  114. ;    Output message
  115.         libcall     Write
  116. NoStdout:    rts
  117.  
  118.         dc.b        '$VER: SaferPatches 2.0 (3-Oct-92)',$0
  119. DOSNAME:    dc.b        'dos.library',0
  120. MESSAGE:    dc.b        $9b,'0;33m','Saferpatches',$9b,'0m installed',$a
  121.         dc.b        '© Martin Adrian 1992',$a
  122. MESSAGE_sizeof    equ        *-MESSAGE
  123. INSTALLED:    dc.b        $9b,'0;33m','SaferPatches',$9b,'0m already installed.',$a
  124. INSTALL_sizeof    equ        *-INSTALLED
  125.  
  126.  
  127.         section     text,code
  128.         xdef        @OldSetFunction
  129.  
  130. @OldSetFunction:
  131.         move.l        A2,-(SP)
  132.         move.l        A6,-(SP)
  133.         move.l        (AbsExecBase).W,A6
  134.         move.l        _OldSetFuncPtr-DT(A4),A2   ; its safe to use A4 here
  135.         jsr        (A2)
  136.         move.l        (SP)+,A6
  137.         move.l        (SP)+,A2
  138.         rts
  139.  
  140.         section     __MERGED,bss
  141.         xdef        _DOSBase
  142.         xdef        _MainHeader
  143.         xdef        _OldSetFuncPtr
  144.         xdef        _SetFuncSemaphore
  145. DT        equ        *
  146. _DOSBase    ds.l        1
  147. _MainHeader    ds.l        1
  148. _OldSetFuncPtr    ds.l        1
  149. _SetFuncSemaphore: ds.b      SS_SIZE
  150.         end
  151.  
  152. ;         xref         _OldSetFuncPtr
  153. ;         xref         _DOSBase
  154. ;         xref         _SetFuncSemaphore
  155. ;         xref         _MainHeader
  156. ;         end
  157.  
  158.